package com.ruoyi.system.service.impl;

import java.util.List;

import com.ruoyi.common.constant.ProjectConstants;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.system.domain.SysExperts;
import com.ruoyi.system.domain.SysProjectInfo;
import com.ruoyi.system.service.ISysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.SysProjectExpertMapper;
import com.ruoyi.system.domain.SysProjectExpert;
import com.ruoyi.system.service.ISysProjectExpertService;

/**
 * 项目评审Service业务层处理
 * 
 * @author riddou
 * @date 2022-04-15
 */
@Service
public class SysProjectExpertServiceImpl implements ISysProjectExpertService 
{
    @Autowired
    private SysProjectExpertMapper sysProjectExpertMapper;

    @Autowired
    private ISysUserService sysUserService;

    /**
     * 查询项目评审
     * 
     * @param reviewId 项目评审主键
     * @return 项目评审
     */
    @Override
    public SysProjectExpert selectSysProjectExpertById(Long reviewId)
    {
        return sysProjectExpertMapper.selectSysProjectExpertById(reviewId);
    }

    /**
     * 查询项目评审列表
     * 
     * @param sysProjectExpert 项目评审
     * @return 项目评审
     */
    @Override
    public List<SysProjectExpert> selectSysProjectExpertList(SysProjectExpert sysProjectExpert)
    {
        return sysProjectExpertMapper.selectSysProjectExpertList(sysProjectExpert);
    }

    /**
     * 新增项目评审
     * 
     * @param sysProjectExpert 项目评审
     * @return 结果
     */
    @Override
    public int insertSysProjectExpert(SysProjectExpert sysProjectExpert)
    {
        sysProjectExpert.setCreateTime(DateUtils.getNowDate());
        return sysProjectExpertMapper.insertSysProjectExpert(sysProjectExpert);
    }

    /**
     * 修改项目评审
     * 
     * @param sysProjectExpert 项目评审
     * @return 结果
     */
    @Override
    public int updateSysProjectExpert(SysProjectExpert sysProjectExpert)
    {
        sysProjectExpert.setUpdateTime(DateUtils.getNowDate());
        return sysProjectExpertMapper.updateSysProjectExpert(sysProjectExpert);
    }

    /**
     * 批量删除项目评审
     * 
     * @param expertIds 需要删除的项目评审主键
     * @return 结果
     */
    @Override
    public int deleteSysProjectExpertByExpertIds(Long[] expertIds)
    {
        return sysProjectExpertMapper.deleteSysProjectExpertByExpertIds(expertIds);
    }

    /**
     * 删除项目评审信息
     * 
     * @param expertId 项目评审主键
     * @return 结果
     */
    @Override
    public int deleteSysProjectExpertByExpertId(Long expertId)
    {
        return sysProjectExpertMapper.deleteSysProjectExpertByExpertId(expertId);
    }

    @Override
    public int buildProjectExpert(SysExperts sysExperts, SysProjectInfo sysProjectInfo, Long type) {
        if (sysExperts == null || sysProjectInfo == null) return 0;
        SysProjectExpert sysProjectExpert = new SysProjectExpert();
        sysProjectExpert.setExpertId(sysExperts.getExpertId());
        sysProjectExpert.setProjectId(sysProjectInfo.getProjectId());

        SysUser sysUser = sysUserService.selectUserByUserName(sysProjectInfo.getCreateBy());

        sysProjectExpert.setUserId(sysExperts.getUserId());
        sysProjectExpert.setProjectState(ProjectConstants.STATE_REVIEWING);
        sysProjectExpert.setType(type);
        sysProjectExpert.setCreateBy("algorithm");
        return insertSysProjectExpert(sysProjectExpert);
    }
}
